﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RFIDStockManagement.BLL;
using RFIDStockManagement.Common.Public.Enums;
using System.IO;
using RFIDStockManagement.Common.Public;

namespace RFIDStockManagement.Client
{
    sealed class LicenseUtil
    {
        public static string LicensePath = AppDomain.CurrentDomain.BaseDirectory + "\\rfidlicense.lic";
        private static string m_EncryptKey = "rfidkkey";
        public static void SaveLicense(string data)
        {
            if (File.Exists(LicensePath))
            {
                File.Delete(LicensePath);
            }
            string enData = Security.EncryptDES(data, m_EncryptKey);
            FileStream stream = new FileStream(LicensePath, FileMode.Create);
            byte[] arrData = new UTF8Encoding().GetBytes(enData);
            stream.Write(arrData, 0, arrData.Length);
            stream.Flush();
            stream.Close();
        }

        public static string GetConnection(string strLicensePath)
        {
            FileStream fs = new FileStream(strLicensePath, FileMode.Open);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);
            fs.Close();
            string enData = new UTF8Encoding().GetString(data);

            return Security.DecryptDES(enData, m_EncryptKey);
        }
        public static string GetConnection()
        {
            string strConn = string.Empty;
            if (File.Exists(LicensePath))
            {
                strConn = GetConnection(LicensePath);
            }


            return strConn;
        }

    }
}
